package com.googlecode.monitoring.ws.model;

import com.googlecode.monitoring.model.EventTime;
import com.googlecode.monitoring.model.ItemToCheck;
import com.googlecode.monitoring.model.Person;
import com.googlecode.monitoring.model.StateName;

import java.util.HashSet;
import java.util.Set;

/**
 * Author: Sergiy Doroshenko
 * Date: Jun 15, 2010
 * Time: 11:36:55 AM
 */
public class WsItemToCheck extends ItemToCheck {

    private TestFrameworkConfig testFrameworkConfig;

    public WsItemToCheck() {
        super();
    }

    public WsItemToCheck(
            String id,
            String name,
            String descr,
            StateName currentStateName
    ) {
        this.setId(id);
        this.name = name;
        this.descr = descr;
        this.setCurrentState(currentStateName);
        this.responsiblePersons = new HashSet<Person>();
    }

    public WsItemToCheck(
            String id,
            String name,
            String descr,
            EventTime eventTime,
            Set<Person> responsiblePersons,
            TestFrameworkConfig testFrameworkConfig,
            StateName currentStateName
    ) {
        this.setId(id);
        this.name = name;
        this.descr = descr;
        this.eventTime = eventTime;
        this.setResponsiblePersons(responsiblePersons);
        this.testFrameworkConfig = testFrameworkConfig;
        this.setCurrentState(currentStateName);
    }

    public TestFrameworkConfig getTestFrameworkConfig() {
        return testFrameworkConfig;
    }

    public void setTestFrameworkConfig(TestFrameworkConfig testFrameworkConfig) {
        this.testFrameworkConfig = testFrameworkConfig;
    }

    public void setCurrentState(StateName currentStateName) {
        this.currentStateName = currentStateName != null ? currentStateName : StateName.NEW;
    }

    @Override
    public String toString() {
        return "WsItemToCheck{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", descr='" + descr + '\'' +
                ", eventTime=" + eventTime +
                ", responsiblePersons=" + responsiblePersons +
                ", testFrameworkConfig=" + testFrameworkConfig +
                ", currentState=" + currentStateName +
                ", lastCheckTime=" + lastCheckTime +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof WsItemToCheck)) return false;

        WsItemToCheck that = (WsItemToCheck) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
   
        return true;
    }

    @Override
	public int hashCode() {
		int result = id.hashCode();
		result = 31 * result + name.hashCode();
		return result;
	}
}
